Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared kernelconnection wrapper #10141

Merged
merged 1 commit into from
May 30, 2022
Merged

Shared kernelconnection wrapper #10141

merged 1 commit into from
May 30, 2022

Conversation

DonJayamanne
Copy link
Contributor

Part of #9503

@codecov-commenter
Copy link

codecov-commenter commented May 26, 2022

Codecov Report

Merging #10141 (aafff02) into main (749d2f3) will decrease coverage by 0%.
The diff coverage is 44%.

❗ Current head aafff02 differs from pull request most recent head 13ecb40. Consider uploading reports for the commit 13ecb40 to get more accurate results

@@          Coverage Diff          @@
##           main   #10141   +/-   ##
=====================================
- Coverage    60%      60%   -1%     
=====================================
  Files       203      204    +1     
  Lines      9240     9286   +46     
  Branches   1492     1502   +10     
=====================================
+ Hits       5632     5650   +18     
- Misses     3130     3154   +24     
- Partials    478      482    +4     
Impacted Files Coverage Δ
src/platform/api/kernelConnectionWrapper.ts 43% <43%> (ø)
src/platform/api/kernelApi.ts 71% <100%> (-2%) ⬇️

public get kernelSocket(): Observable<KernelSocketInformation | undefined> {
return this._kernelSocket;
}
public get onSessionStatusChanged(): Event<KernelMessage.Status> {
return this.onStatusChangedEvent.event;
}
public get onIOPubMessage(): Event<KernelMessage.IIOPubMessage> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to hook up to the iopub and anymessage events in the underlyiing Jupyter kernel connection.
This property onIOPubMessage is a custom event we wire up. If I were to introduce anyMessage event then i'd have to handle kernel restarts all over again, tomorrow if we wanted to handle other events, then all over gain etc...

Also, as we expose the underlying jupyter kernel (Kernel.IKenrelConnection) everywhere it makes sense to just hook to those events.

Hence created a kernel wrapper so that we have a single instance, of the Kernel.KernleConnection on which we can monitor the events (basically moved onIOPubMessage & similar events into the kernel.IKernelConnection and have that keep track of all the event handlers even when kernels restart)

}
}
})
new Disposable(() => this.jupyterSession.kernel?.iopubMessage.disconnect(this.onIOPubMessage, this))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we can hook up to the underlying Jupyter API events.

import { BaseKernelConnectionWrapper } from '../../kernels/jupyter/baseKernelConnectionWrapper';
import { IKernel } from '../../kernels/types';

export class KernelConnectionWrapper extends BaseKernelConnectionWrapper {
Copy link
Contributor Author

@DonJayamanne DonJayamanne May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existing wrapper around IKernel for 3rd party API (modifeid to share code)
This wrapper wrap the IKernel object, instead of directly exposing the jupyter API as the IKernel object handles restarts, interrupts, & all of those details.

@@ -51,9 +51,6 @@ export class RawJupyterSession extends BaseJupyterSession {
}
return super.status;
}
public get kernelId(): string {
return this.session?.kernel?.id || '';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code in both child classes, moved to base class

@@ -76,15 +69,6 @@ export class JupyterSession extends BaseJupyterSession implements IJupyterServer
// Wait for idle on this session
return this.waitForIdleOnSession(this.session, timeout);
}

public override get kernel(): Kernel.IKernelConnection | undefined {
return this.session?.kernel || undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code in both child classes, moved to base class

@DonJayamanne DonJayamanne marked this pull request as ready for review May 26, 2022 23:43
@DonJayamanne DonJayamanne requested a review from a team as a code owner May 26, 2022 23:43
@DonJayamanne DonJayamanne requested a review from rchiodo May 27, 2022 00:08
@DonJayamanne DonJayamanne force-pushed the kernelConnectionWrapper branch 2 times, most recently from edb849d to aafff02 Compare May 30, 2022 00:42
@DonJayamanne DonJayamanne force-pushed the kernelConnectionWrapper branch from aafff02 to 13ecb40 Compare May 30, 2022 04:44
@DonJayamanne DonJayamanne merged commit 4a2cd14 into main May 30, 2022
@DonJayamanne DonJayamanne deleted the kernelConnectionWrapper branch May 30, 2022 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants